﻿using System;

namespace Library.OrmEnterpriseEntity.TableInfo {
	///<summary>
	///</summary>
	public class ByteArrayColumn : Column<Byte[]> {
		protected readonly ByteArrayColumnView ByteArrayMetadata;

		internal static readonly Type ByteArrayColumnType = typeof(ByteArrayColumn);
		///<summary>
		///</summary>
		public static readonly Byte[] DefaultByteArray = new byte[0];
		

		//}
		/// <summary>
		/// 
		/// </summary>
		/// <param name="metadata"></param>
		/// <param name="table"></param>
		public ByteArrayColumn(ByteArrayColumnView metadata, DbTable table)
			: base(metadata, table) {
			ByteArrayMetadata = metadata;
		}

		/// <summary>
		/// Len is -1, mean use max len
		/// </summary>
		public virtual int Len { get { return ByteArrayMetadata.Len; } }
		
		protected override byte[] Default {
			get { return DefaultByteArray; }
		}


		//public override DbType DbType {
		//  get { return DbType.Binary; }
		//}

		protected override byte[] ConvertFrom(object value) {
			return (byte[])value;
		}

		protected override bool Equal(byte[] t1, byte[] t2) {
			return t1 == t2;
		}
		internal override bool ValueNotDefault {
			get { return Value != DefaultByteArray; }
		}

	}
}
